const fetchUtil = {
    doPost:function (url,data) {
        return fetch(url, {
                method: 'POST', // or 'PUT'
                body: JSON.stringify(data), // data can be `string` or {object}!
                headers: new Headers({
                    'Content-Type': 'application/json'
                })
            }).then(res => res.json())
    },
    // postData('http://example.com/answer', {answer: 42})
    // .then(data => console.log(data))
    // .catch(error => console.error(error))
    doPost1:function(url,data){
        return fetch(url, {
                body: JSON.stringify(data), // must match 'Content-Type' header
                cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
                credentials: 'same-origin', // include, same-origin, *omit
                headers: {
                    'user-agent': 'Mozilla/4.0 MDN Example',
                    'content-type': 'application/json'
                },
                method: 'POST', // *GET, POST, PUT, DELETE, etc.
                mode: 'cors', // no-cors, cors, *same-origin
                redirect: 'follow', // manual, *follow, error
                referrer: 'no-referrer', // *client, no-referrer
            }).then(response => response.json()) // parses response to JSON
    },
    doUpload:function (url,inputFileId) {
        var formData = new FormData();
        var fileField = document.querySelector("#"+inputFileId);
        formData.append('username', 'abc123');
        formData.append('avatar', fileField.files[0]);
        fetch(url, {
            method: 'PUT',
            body: formData
        })
            .then(response => response.json())
        .catch(error => console.error('Error:', error))
        .then(response => console.log('Success:', response));
    }
}